package com.qf.controller;

import com.github.pagehelper.PageInfo;
import com.qf.entity.BillType;
import com.qf.entity.Bills;
import com.qf.service.BillsService;
import com.qf.util.PageUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐老板
 * @date 2020/3/26   10:19
 */
@Controller
public class BillsController {
    @Resource
    private BillsService billsService;

    @RequestMapping("/getbills")
    //因为要实现的是页面跳转 所以这里用的是string
    public String getBills(@RequestParam(defaultValue = "1")int pageIndex,
                           @RequestParam(defaultValue = "-1")int typeId,
                           String beginTime, String endTime, ModelMap modelMap){
        PageInfo<Bills> pageInfo = billsService.findAll(pageIndex, PageUtils.PAGESIZE, typeId,
                beginTime, endTime);

        modelMap.addAttribute("pi", pageInfo);
        //接下来写下拉框的内容
        List<BillType> typeList = billsService.findType();
        modelMap.addAttribute("billtypes", typeList);
        //接下来这三个做数据回显用 数据回显的原理是从前端传过来的值再有modelmap返回给前端
        modelMap.addAttribute("tid", typeId);
        modelMap.addAttribute("beginTime", beginTime);
        modelMap.addAttribute("endTime", endTime);

        return "showbill";

    }
}
